package main.com.dhj.test03

import scala.util.Random


object test01 {

    def main(args: Array[String]): Unit = {

        val customer1ID = CustomerID("Sukyoung");
        println(customer1ID);
        customer1ID match {
            case CustomerID(name) => println(name)
            case _ => println("Could not extract a CustomerID")
        }

    }

    private object CustomerID {
        // 这是一个隐式转换，scala插值器
        def apply(name: String) = s"$name--${Random.nextLong}"

        def unapply(customerID: String): Option[String] = {
            val stringArray: Array[String] = customerID.split("--")
            if (stringArray.tail.nonEmpty) Some(stringArray.head) else None
        }
    }


}

